package pl.skubicha.controller.property.editors;

import java.beans.PropertyEditorSupport;

import pl.skubicha.domain.Users;
import pl.skubicha.exceptions.UserNotFoundException;
import pl.skubicha.service.UserService;

public class UsersPropertyEditor extends PropertyEditorSupport {

	private final UserService userService;

	public UsersPropertyEditor( final UserService userService ) {
		this.userService = userService;
	}

	@Override
	public void setAsText( final String text ) throws IllegalArgumentException {
		Users user = null;
		try {
			user = userService.findById( Integer.parseInt( text ) );
		} catch ( UserNotFoundException e ) {			
		}
		setValue( user );
	}

}
